package com.example.sunmiv1.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.ReportLossGoodBean;
import com.example.sunmiv1.entity.StockInquiryGoodBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StockInquiryAdapter extends BaseAdapter {

    private Context context;
    private List<StockInquiryGoodBean.ListBean> list;
    private ViewHolder viewHolder;

    public StockInquiryAdapter(Context context, List<StockInquiryGoodBean.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.stock_inquiry_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Resources resources = context.getResources();
        viewHolder.stockInquiryAdapterName.setText(resources.getString(R.string.inventory_name) + list.get(position).getGoods_name());
        viewHolder.stockInquiryAdapterFreightNumber.setText(resources.getString(R.string.inventory_freightNumber) +
                list.get(position).getGoods_number());
        viewHolder.stockInquiryAdapterBarcode.setText(resources.getString(R.string.priceQuery_code) + list.get(position).getGoods_code());
        viewHolder.stockInquiryAdapterPurchasePrice.setText(resources.getString(R.string.inventory_purchasePrice) +
                list.get(position).getCost_price());
//        if ("".equals(list.get(position).getCheck_num())) {
//            viewHolder.stockInquiryAdapterInventory.setText(resources.getString(R.string.inventory_inventory) + resources.getString(R.string.inventory_noInventory));
//        } else {
//            viewHolder.stockInquiryAdapterInventory.setText(resources.getString(R.string.inventory_inventory) + list.get(position).getCheck_num());
//        }
        viewHolder.stockInquiryAdapterStock.setText(resources.getString(R.string.inventory_stock) + list.get(position).getGoods_num());
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.stockInquiry_adapter_name)
        TextView stockInquiryAdapterName;
        @BindView(R.id.stockInquiry_adapter_freightNumber)
        TextView stockInquiryAdapterFreightNumber;
        @BindView(R.id.stockInquiry_adapter_barcode)
        TextView stockInquiryAdapterBarcode;
        @BindView(R.id.stockInquiry_adapter_purchasePrice)
        TextView stockInquiryAdapterPurchasePrice;
        @BindView(R.id.stockInquiry_adapter_stock)
        TextView stockInquiryAdapterStock;
        @BindView(R.id.stockInquiry_adapter_price)
        TextView stockInquiryAdapterPrice;
        @BindView(R.id.stockInquiry_adapter_inventory)
        TextView stockInquiryAdapterInventory;
        @BindView(R.id.stockInquiry_adapter_inventorying)
        TextView stockInquiryAdapterInventorying;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
